package cn.gailvlun.gll.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.WindowManager;

import com.blankj.utilcode.util.ConvertUtils;

import cn.gailvlun.gll.net.R;
import cn.gailvlun.gll.net.databinding.DialogProgressBinding;
import cn.gailvlun.gll.widget.RotatedDrawable;




public class ProgressDialog extends Dialog {

    private DialogProgressBinding mBinding;
    private RotatedDrawable mRotatedDrawable;

    public ProgressDialog(@NonNull Context context) {
        super(context, R.style.ProgressDialog);
        mBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.dialog_progress, null, false);

        mRotatedDrawable = new RotatedDrawable();
        mRotatedDrawable.setBitmap(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.spinner));

        mBinding.iv.setImageDrawable(mRotatedDrawable);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(mBinding.getRoot());

        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = ConvertUtils.dp2px(100);
        lp.height = ConvertUtils.dp2px(100);
        getWindow().setAttributes(lp);
    }


    @Override
    protected void onStart() {
        super.onStart();
        mRotatedDrawable.start();
    }

    @Override
    protected void onStop() {
        mRotatedDrawable.stop();
        super.onStop();
    }
}
